package com.damai.action.json;

import java.io.IOException;
import java.util.Map;

import com.citywithincity.api.entities.Customer;
import com.citywithincity.crypt.CryptFactory;
import com.citywithincity.crypt.IDataCrypt;
import com.citywithincity.utils.JsonUtil;
import com.damai.annotation.UploadFileList;
import com.damai.error.ApiError;

public class FileDecryptParamParser extends FileParamParser {
	private IDataCrypt crypt = CryptFactory.getDataCrypt();
	

	public FileDecryptParamParser(UploadFileList list) {
		super(list);
	}

	
	@Override
	protected Map<String, Object> read(byte[] bytes, Customer customer) throws IOException {
		try {
			bytes = crypt.decript(bytes, customer.getPinKey());
		} catch (Exception e) {
			throw new ApiError("数据解密失败，请稍后重试");
		}
		return JsonUtil.read(bytes);
	}
}
